#include "showSetting.h"

ShowSetting::ShowSetting()
{
    m_ShowSettingLayout = new QVBoxLayout(this);

    m_GammaLayout       = new QHBoxLayout();
    m_GammaLabel        = new QLabel();
    m_GammaSB           = new QDoubleSpinBox();
    m_GammaSlider       = new DoubleSlider();
    m_GammaLayout       ->addWidget(m_GammaLabel);
    m_GammaLayout       ->addWidget(m_GammaSB);
    m_ShowSettingLayout ->addLayout(m_GammaLayout);
    m_ShowSettingLayout ->addWidget(m_GammaSlider);
    m_GammaSB->setFixedSize(60, 25);
    //m_GammaLayout->setSizeConstraint()

    m_CompLayout        = new QHBoxLayout();
    m_CompLabel         = new QLabel();
    m_CompSB            = new QDoubleSpinBox();
    m_CompSlider        = new DoubleSlider();
    m_CompLayout        ->addWidget(m_CompLabel);
    m_CompLayout        ->addWidget(m_CompSB);
    m_ShowSettingLayout ->addLayout(m_CompLayout);
    m_ShowSettingLayout ->addWidget(m_CompSlider);
    m_CompSB->setFixedSize(60, 25);

    m_LumLayout         = new QHBoxLayout();
    m_LumLabel          = new QLabel();
    m_LumSB             = new QSpinBox();
    m_LumSlider         = new DoubleSlider();
    m_LumLayout         = new QHBoxLayout();
    m_LumLayout         ->addWidget(m_LumLabel);
    m_LumLayout         ->addWidget(m_LumSB);
    m_ShowSettingLayout ->addLayout(m_LumLayout);
    m_ShowSettingLayout ->addWidget(m_LumSlider);
    m_LumSB->setFixedSize(60, 25);

    m_ChromaLayout      = new QHBoxLayout();
    m_ChromaLabel       = new QLabel();
    m_ChromaSB          = new QSpinBox();
    m_ChromaSlider      = new DoubleSlider();
    m_ChromaLayout      ->addWidget(m_ChromaLabel);
    m_ChromaLayout      ->addWidget(m_ChromaSB);
    m_ShowSettingLayout ->addLayout(m_ChromaLayout);
    m_ShowSettingLayout ->addWidget(m_ChromaSlider);
    m_ChromaSB->setFixedSize(60, 25);

    ShowSettingInit();
    LanguageInit();
    this->setLayout(m_ShowSettingLayout);
    this->setFixedHeight(220);
}

int ShowSetting::RFixedHeight()
{
    return m_FixedHeight;
}

int ShowSetting::fixedWidth(ParameterKind kind, int widget)
{
    return 0;
}

bool ShowSetting::setPaletteBF(const QPalette &palette)
{
    this->setPalette(palette);
    this->setAutoFillBackground(true);

    foreach(QObject *child, this->children())
    {
        if(QWidget* childWidget = qobject_cast<QWidget*>(child))
        {
            childWidget->setPalette(palette);
            this->setAutoFillBackground(true);
        }
    }
    return true;
}

void ShowSetting::LanguageInit()
{
    m_GammaLabel->  setText(tr("伽马"));
    m_CompLabel->   setText(tr("对比度"));
    m_LumLabel->    setText(tr("亮度"));
    m_ChromaLabel-> setText(tr("饱和度"));
}

void ShowSetting::ShowSettingInit()
{
    m_GammaSlider-> setRange(1, 2);
    m_GammaSB->setMinimum(1);
    m_GammaSB->setMaximum(2);
    m_GammaSB->setSingleStep(0.1); // 设置步长为0.1
    m_GammaSB->setValue(1);
    m_GammaSlider->setValue(1);

    m_CompSlider->  setRange(1, 10);
    m_CompSB->setMinimum(1);
    m_CompSB->setMaximum(10);
    m_CompSB->setSingleStep(0.1); // 设置步长为0.1
    m_CompSB->setValue(1);
    m_CompSlider->setValue(1);

    m_LumSlider->   setRange(1, 100);
    m_ChromaSlider->setRange(1, 100);


    connect(m_GammaSlider, &DoubleSlider::valueChanged, this, [=](double value){
        m_GammaSB->setValue(value);
        senderValue(signalKind::GAMMA, value);
    });
    connect(m_CompSlider, &DoubleSlider::valueChanged, this, [=](double value){
        m_CompSB->setValue(value);
        senderValue(signalKind::COMP, value);
    });
    connect(m_LumSlider, &DoubleSlider::valueChanged, this, [=](double value){
        m_LumSB->setValue(value);
        senderValue(signalKind::LUM, value);
    });
    connect(m_ChromaSlider, &DoubleSlider::valueChanged, this, [=](double value){
        m_ChromaSB->setValue(value);
        senderValue(signalKind::CHROMA, value);
    });

    connect(m_GammaSB, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, [=](double value){
        m_GammaSlider->setValue(value);
        senderValue(signalKind::GAMMA, value);
    });

    connect(m_CompSB, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, [=](double value){
        m_CompSlider->setValue(value);
        senderValue(signalKind::COMP, value);
    });
    connect(m_LumSB, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, [=](int value){
        m_LumSlider->setValue(value);
        senderValue(signalKind::LUM, value);
    });
    connect(m_ChromaSB, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, [=](int value){
        m_ChromaSlider->setValue(value);
        senderValue(signalKind::CHROMA, value);
    });

}
